import { ref } from 'vue'

// 简单的 EventBus 实现
class EventBus {
  constructor() {
    this.events = {}
  }

  // 监听事件
  on(eventName, callback) {
    if (!this.events[eventName]) {
      this.events[eventName] = []
    }
    this.events[eventName].push(callback)
  }

  // 触发事件
  emit(eventName, data) {
    const event = this.events[eventName]
    if (event) {
      event.forEach(fn => {
        fn(data)
      })
    }
  }

  // 移除事件监听
  off(eventName, callback) {
    const event = this.events[eventName]
    if (event) {
      this.events[eventName] = event.filter(fn => fn !== callback)
    }
  }
}

export default new EventBus()
